{% extends "exam_system/base.html" %}
{% load static %}

{% block content %}
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    <h3 class="text-center">考生登录</h3>
                </div>
                <div class="card-body">
                    {% if messages %}
                    <div class="messages">
                        {% for message in messages %}
                        <div class="alert alert-{{ message.tags }}">
                            {{ message }}
                        </div>
                        {% endfor %}
                    </div>
                    {% endif %}

                    <form method="post">
                        {% csrf_token %}
                        {% if form.non_field_errors %}
                            <div class="alert alert-danger">
                                {% for error in form.non_field_errors %}
                                    {{ error }}
                                {% endfor %}
                            </div>
                        {% endif %}
                        <div class="form-group mb-3">
                            <label for="phone">手机号码</label>
                            <input type="tel" class="form-control" id="phone" name="phone" required>
                        </div>
                        <div class="form-group mb-3">
                            <label for="password">密码</label>
                            <input type="password" class="form-control" id="password" name="password" required>
                            {% if form.password.errors %}
                                <div class="invalid-feedback d-block">
                                    {{ form.password.errors }}
                                </div>
                            {% endif %}
                        </div>
                        {% if show_captcha %}
                            <div class="form-group mb-3">
                                <label for="captcha">验证码</label>
                                {{ form.captcha }}
                                {% if form.captcha.errors %}
                                    <div class="invalid-feedback d-block">
                                        {{ form.captcha.errors }}
                                    </div>
                                {% endif %}
                                <a href="#" class="refresh-captcha">刷新验证码</a>
                            </div>
                        {% endif %}
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">登录</button>
                        </div>
                        <div class="text-center mt-3">
                            还没有账号？<a href="{% url 'exam_system:register' %}">立即注册</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}